﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EazyNoteBook
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 重置账号和密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            Notebook.WordWrap = true;
            if (button3.Text.Equals("取消自动换行"))
            {
                Notebook.WordWrap = false;
                button3.Text = "自动换行";
            }
            else {
                Notebook.WordWrap = true;
                button3.Text = "取消自动换行";
            }
        }
        /// <summary>
        /// 登录检测输入账号和密码是否是对的
        /// Visible对其进行出场顺序的优化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (username.Text.Equals("zhaowei") && Password.Text.Equals("123456"))
            {
                username.Visible = false;
                Password.Visible = false;
                label1.Visible = false;
                label2.Visible = false;
                button1.Visible = false;
                button2.Visible = false;
                Notebook.Visible = true;
                button3.Visible = true;
                button4.Visible = true;
                MessageBox.Show("登录成功！请使用笔记本");
            }
            else {
                MessageBox.Show("密码不对无法进入");
                username.Clear();
                Password.Clear();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream(@"D:\C#project\EazyNoteBook\eznoteBook.txt", FileMode.OpenOrCreate, FileAccess.Write)) {
                String trim = Notebook.Text.ToString();
                Byte[] bt = System.Text.Encoding.Default.GetBytes(trim);
                fs.Write(bt,0,bt.Length);
             }
            MessageBox.Show("保存成功");
        }
    }
}
